package com.anglireports.report.bean.report;

import com.anglireports.report.bean.base.BaseBean;
import com.anglireports.report.response.util.CommonUtils;

import java.util.List;

/**
 * 报告-学生活跃度
 * @author lvjilei
 * @ceateTime 2019/3/25.
 */
public class Vitality extends BaseBean{
    /**
     * 侦测到活跃度为「离线」的次数。
     */
    private Integer extreme;

    /**
     * 侦测到活跃度为「活泼」的次数。
     */
    private Integer vivacious;

    /**
     * 侦测到活跃度为「活泼」的次数。
     */
    private Integer lively;

    /**
     * 侦测到活跃度为「普通」的次数。
     */
    private Integer normal;

    /**
     * 侦测到活跃度为「瞌睡」的次数。
     */
    private Integer offline;

    public Vitality() {
    }

    public Vitality(Integer extreme, Integer vivacious, Integer lively, Integer normal, Integer offline) {
        this.extreme = extreme;
        this.vivacious = vivacious;
        this.lively = lively;
        this.normal = normal;
        this.offline = offline;
    }


    public Integer getExtreme() {
        return extreme;
    }

    public void setExtreme(Integer extreme) {
        this.extreme = extreme;
    }

    public Integer getVivacious() {
        return vivacious;
    }

    public void setVivacious(Integer vivacious) {
        this.vivacious = vivacious;
    }

    public Integer getLively() {
        return lively;
    }

    public void setLively(Integer lively) {
        this.lively = lively;
    }

    public Integer getNormal() {
        return normal;
    }

    public void setNormal(Integer normal) {
        this.normal = normal;
    }

    public Integer getOffline() {
        return offline;
    }

    public void setOffline(Integer offline) {
        this.offline = offline;
    }

    /**
     * 根据计算规则计算出活跃度分数.
     * @return
     */
    public Float getVitalityData(){
        return CommonUtils.getNum((0 * offline + 25 * normal +
                50 * lively + 75 * vivacious + 100 * extreme)/
                (float)(offline + normal + lively + vivacious + extreme), "0.0");

    }

    /**
     * 1-20:1顆星
     21-40: 2顆星
     41-60: 3顆星
     61-80: 4顆星
     81-100: 5顆星
     * @return
     */
    public Integer getCanyudu(){
        Float score = this.getVitalityData();
        if(score >=0 && score <= 20){
            return 1;
        } else if (score >=21 && score <= 40){
            return 2;
        } else if (score >=41 && score <= 60){
            return 3;
        } else if (score >=61 && score <= 80){
            return 4;
        } else if (score >=81 && score <= 100){
            return 5;
        }
        return 0;
    }

    public static Vitality getVitalityAvg(List<Vitality> list){
        Vitality vitality = new Vitality();
        Integer normal = 0;
        Integer extreme = 0;
        Integer lively = 0;
        Integer offline = 0;
        Integer vivacious = 0;

        for (Vitality v : list){
            normal += v.getNormal();
            extreme += v.getExtreme();
            lively += v.getLively();
            offline += v.getOffline();
            vivacious += v.getVivacious();
        }

        vitality.setNormal(normal/list.size());
        vitality.setExtreme(extreme/list.size());
        vitality.setLively(lively/list.size());
        vitality.setOffline(offline/list.size());
        vitality.setVivacious(vivacious/list.size());
        return vitality;
    }


    public Vitality megreVitality(Vitality vitality){
        this.setNormal(this.getNormal() + vitality.getNormal());
        this.setExtreme(this.getExtreme() + vitality.getExtreme());
        this.setLively(this.getLively() + vitality.getLively());
        this.setOffline(this.getOffline() + vitality.getOffline());
        this.setVivacious(this.getVivacious() + vitality.getVivacious());
        return this;
    }
}
